package xing.service.controller;

import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import xing.application.api.OwnerRequireAndAiApi;
import xing.infrastructure.data.CallResult;

/*******************************************************************************************
 * 类描述：  
 *
 * @author: dustin
 * @date: 2017-11-06 16:40
 * @Description:
 * @version 1.0
 *
 *
 * Version    Date       ModifiedBy                 Content  
 * -------- ---------    ----------         ------------------------  
 * 1.0      2017/11/6     dst                               
 *******************************************************************************************
 */
@Api(value = "业主报事+智能空间",description = "")
@RestController
@RequestMapping("/owner")
public class OwnerController {

    @Autowired
    OwnerRequireAndAiApi ownerRequireAndAiApi;

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @ApiOperation(value="报事+智能管家列表", notes="")
    @ApiImplicitParams({@ApiImplicitParam(name = "searchText", value = "搜索文字", dataType = "String", paramType = "query" ),
            @ApiImplicitParam(name = "searchType", value = "搜索类型 (finished，unfinish，unstart，indo，expire)", dataType = "String", paramType = "query" ),
            @ApiImplicitParam(name = "compositeName", value = "排序名称 (startTime,endTime)", dataType = "String", paramType = "query" ),
            @ApiImplicitParam(name = "compositeType", value = "排序类型 （desc，asc）", dataType = "String", paramType = "query" )
    })
    @GetMapping("/list/{phone}")
    public String getReqList(@PathVariable String phone, @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
                             @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                             @RequestParam(defaultValue = "") String searchText, @RequestParam(defaultValue = "") String searchType, @RequestParam(defaultValue = "") String compositeName, @RequestParam(defaultValue = "") String compositeType){

        String res;
        try {
            res = ownerRequireAndAiApi.getRequireAndAiList(phone,pageNo,pageSize,searchText,searchType,compositeName,compositeType);
        } catch (Exception e) {
            logger.error("获取报事+智能空间列表失败 ",e);
            res = JSON.toJSONString( new CallResult(-1,"获取报事+智能空间列表失败",null));
        }
        return res;
    }

    @ApiOperation(value="状态数量", notes="")
    @GetMapping("/status/{phone}")
    public String getReqStatus(@PathVariable String phone){

        String res;
        try {
            res = ownerRequireAndAiApi.getStatusCount(phone);
        } catch (Exception e) {
            logger.error("获取状态数量失败 ",e);
            res = JSON.toJSONString( new CallResult(-1,"获取状态数量失败",null));
        }
        return res;
    }

    @ApiOperation(value="获取消息未读数", notes="")
    @GetMapping("/unread/{phone}")
    public String getUnReadMsgCount(@PathVariable String phone){

        String res;
        try {
            res = ownerRequireAndAiApi.getUnReadMsgCount(phone);
        } catch (Exception e) {
            logger.error("获取消息未读数失败 ",e);
            res = JSON.toJSONString( new CallResult(-1,"获取消息未读数失败",null));
        }
        return res;
    }
}
